<template>
  <div class="nav-header">
    <div class="left-container">
      <div @click="handleFoldClick">
        <template v-if="isFold">
          <el-icon :size="30"><Expand /></el-icon>
        </template>

        <template v-else>
          <el-icon :size="30"><Fold /></el-icon>
        </template>
      </div>
      <breadcrumb :breadcrumb="breadcrumbs"></breadcrumb>
    </div>

    <user-info></user-info>
  </div>
</template>

<script lang="ts">
import { defineComponent, computed, ref } from 'vue'

import breadcrumb from '@/base-ui/breadcrumb'

import userInfo from '../user-info.vue'

import { pathMapToMenu } from '@/utils/map-menu'

import { useStore } from 'vuex'
import { useRoute } from 'vue-router'
import type { IBreadcrumb } from '@/base-ui/breadcrumb/types'

export default defineComponent({
  emits: ['foldChange'],
  setup(props, { emit }) {
    //1:
    const store = useStore()
    const route = useRoute()
    const isFold = ref(false)

    //2:computed计算属性
    const breadcrumbs = computed(() => {
      let breadcrumbs: IBreadcrumb[] = []
      pathMapToMenu(store.state.login.userMenus, route.path, breadcrumbs)
      return breadcrumbs
    })

    //3:处理展开、折叠点击
    const handleFoldClick = () => {
      isFold.value = !isFold.value
      emit('foldChange', isFold.value)
    }

    return {
      isFold,
      breadcrumbs,
      handleFoldClick
    }
  },
  components: {
    breadcrumb,
    userInfo
  }
})
</script>

<style scoped lang="less">
.nav-header {
  width: 100%;
  display: flex;
  justify-content: space-between;
  align-items: center;
  .left-container {
    display: flex;
    align-items: center;
  }
}
</style>
